#pragma once

#include <string>
#include <sstream>

class XmlElement
{
public:
	static std::string Create(const char *name, const char *value, int identityLevel);
	static std::string CreateCdata(const char *value, int identityLevel);
	static std::string OpenTag(const char *name, int identityLevel);
	static std::string OpenTagWithAttribs(const char *name, int identityLevel);

	template <typename ValType>
	static std::string CreateTagWithData(const char *name, ValType data, int identityLevel)
	{
		std::string identity;
		for (int i = 0; i < identityLevel; i++)
			identity += "\t";

		std::stringstream ret;
		ret << identity << "<" << name << ">" << data << "</" << name << ">\n";
		return ret.str();
	}

	template <typename ValType>
	static std::string CreateAttrib(const char *name, ValType value)
	{
		std::stringstream ret;
		ret << name << "=\"" << value << "\" ";
		return ret.str();
	}

	template <typename ValType>
	static std::string CreateLastAttrib(const char *name, ValType value)
	{
		std::stringstream ret;
		ret << CreateLastAttrib<ValType>(name, value, false);
		return ret.str();
	}

	template <typename ValType>
	static std::string CreateLastAttrib(const char *name, ValType value, bool closeTag)
	{
		std::stringstream ret;
		if (closeTag)
			ret << name << "=\"" << value << "\" />\n";
		else
			ret << name << "=\"" << value << "\">\n";
		return ret.str();
	}

	static std::string CloseTag(const char *name, int identityLevel);
};
